#include <stdio.h>
#include <stdlib.h>	/* exit() */
#include <string.h>
#include <pthread.h>
#include <sys/time.h>
#include <time.h>
#include <limits.h>
#include <errno.h>
#include <signal.h>
#include <setjmp.h>


/*
 * setjmp and longjmp
 */

#define TOK_ADD	5

jmp_buf jmpbuffer;


void do_line(char *);
void cmd_add(void);
int get_token(void);


int main(void)
{
	char line[1024];

	if ( setjmp(jmpbuffer) != 0)
		perror("error");

	while (fgets(line, 1024, stdin) != NULL)
		do_line(line);

	exit(0);
}

char *tok_ptr;	/* global pointer for get_token() */

void do_line(char * ptr)	/* process one line of input */
{
	int cmd;

	tok_ptr = ptr;

	while ((cmd = get_token()) > 0) {
		switch (cmd) {	/* one case for each command */
			case TOK_ADD:
				cmd_add();
				break;
		}
	}
}

void cmd_add(void)
{
	int token;

	token = get_token();

	if (token < 0)	/* an error has occurred */
		longjmp(jmpbuffer, 1);

	/* rest of processing for this command */
}

int get_token(void)
{
	/* fetch next token from line pointed to by tok_ptr */
}



